package tech.aistar.prj.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 本类功能:该监听器负责将项目的上下文路径放入到application作用域中
 *
 * @author cxylk
 * @date 2020/9/20 23:05
 */
@WebListener
public class PathListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext=servletContextEvent.getServletContext();
        //项目的上下文路径
        String path=servletContext.getContextPath();

        System.out.println(path);

        //放入到application作用域
        servletContext.setAttribute("path",path);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
